package com.wjc.train.business.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.business.req.TrainQueryReq;
import com.wjc.train.business.req.TrainSaveReq;
import com.wjc.train.business.resp.TrainQueryResp;
import com.wjc.train.business.service.ITrainSeatService;
import com.wjc.train.business.service.ITrainService;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 车次表 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-07-31
 */
@RestController
@Validated
@RequestMapping("/admin/train")
public class TrainController {

    @Resource
    private ITrainService trainService;
    @Resource
    private ITrainSeatService trainSeatService;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid TrainSaveReq trainSaveReq){
        trainService.save(trainSaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp queryList(@RequestBody TrainQueryReq trainQueryReq){
        IPage<TrainQueryResp> iPage =
        trainService.queryList(PageUtil.getPage(trainQueryReq.getQueryPage()), trainQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        trainService.delete(id);
        return CommonResp.success();
    }

    @GetMapping("/query-all")
    public CommonResp queryAll(){
        return CommonResp.success(trainService.queryAll());
    }

    @GetMapping("/gen-seat/{trainCode}")
    public CommonResp genTrainSeat(@PathVariable String trainCode){
        trainSeatService.genTrainSeat(trainCode);
        return CommonResp.success();
    }

}


